//math grades
	use "$path/Auxiliary/results/math_std_estimates.dta",clear

	//Sort
	gsort -beta
	//Rank 
	gen rank=_n
	
	//Gen indicators and scatters
		local scoff=" "
		local scon=" "
		local ind=-0.11
		foreach var in main_sample full_sample data_books data_actas controls pooled year_2014 year_2015{
			cap gen i_`var' = `ind'
			local ind = `ind'-0.015

				
			local scoff = "`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs14) $mlabel)" 
			local scon =" `scon' (scatter i_`var' rank if `var'==1, msize(vsmall) mcolor(black))"

			if "`var'" == "data_books" | "`var'" == "data_actas" {
				replace i_`var' = i_`var' - 0.015
			}
			
			if "`var'" == "controls" {
				replace i_`var' = i_`var' - 0.03
			}

			if "`var'" == "pooled" | "`var'" == "year_2014" |  "`var'" == "year_2015"{
				replace i_`var' = i_`var' - 0.045
			}
		}
		 
	tw  (scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)) ///
		(rcap u95 l95 rank, lcolor(gs5)) ///
		(rspike u90 l90 rank, lcolor(gs14)) ///
		(scatter beta rank, mcolor(black) msymbol(oh) msize(small)) ///
		`scoff' `scon' ///
		(scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)), ///
        legend (order(1 "Main spec." 4 "Point estimate" 2 "95% CI" 3 "90% CI") region(lcolor(white)) ///
		region(lcolor(white)) pos(12) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
		graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		xtitle(" ") ytitle(" ") yscale(noline) xscale(noline) ///
		ylab(-0.05(0.05)0.25, format(%9.2fc) noticks nogrid angle(horizontal) labsize(small)) ///
		yline(0, lp(shortdash) lcolor(red) lw(thin)) xlab("", noticks)   
	   
		global legend custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))))
		gr_edit .yaxis1.add_ticks -0.11 `"Sample                         "', $legend
		gr_edit .yaxis1.add_ticks -0.11  `"Main  "', $legend
		gr_edit .yaxis1.add_ticks -0.125  `"Full  "', $legend
		gr_edit .yaxis1.add_ticks -0.155 `"Data                         "', $legend
		gr_edit .yaxis1.add_ticks -0.155 `"Books  "', $legend
		gr_edit .yaxis1.add_ticks -0.170 `"School Records  "', $legend
		gr_edit .yaxis1.add_ticks -0.2 `"Controls                         "', $legend
		gr_edit .yaxis1.add_ticks -0.23 `"Period                         "', $legend
		gr_edit .yaxis1.add_ticks -0.23 `"Pooled     "', $legend
		gr_edit .yaxis1.add_ticks -0.245 `"2014     "',$legend
		gr_edit .yaxis1.add_ticks -0.26 `"2015     "', $legend
		
		gr save "$path/Auxiliary/results/math.gph", replace	
		gr export "$path/Auxiliary/results/math_rob.png", replace  //wid(700) hei(500) 	
		*(scatter beta rank if _n==7, mcolor(white) msymbol(oh) msize(small)) ///

//highgrade	
	use "$path/Auxiliary/results/highgrade_estimates.dta",clear

	//Sort
	gsort -beta
	//Rank 
	gen rank=_n
	//Gen indicators and scatters
		local scoff=" "
		local scon=" "
		local ind=-0.-0.05 //-0.25
		foreach var in main_sample full_sample data_books data_actas controls pooled year_2014 year_2015{
			cap gen i_`var' = `ind'
			local ind = `ind'-0.005
				
			local scoff = "`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs14) $mlabel)" 
			local scon =" `scon' (scatter i_`var' rank if `var'==1, msize(vsmall) mcolor(black))"

			if "`var'" == "data_books" | "`var'" == "data_actas" {
				replace i_`var' = i_`var' -0.005
			}
			
			if "`var'" == "controls" {
				replace i_`var' = i_`var' -0.01
			}

			if "`var'" == "pooled" | "`var'" == "year_2014" |  "`var'" == "year_2015"{
				replace i_`var' = i_`var' - 0.015
			}
		}
		 
		 
	tw  (scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)) ///
		(rcap u95 l95 rank, lcolor(gs5)) ///
		(rspike u90 l90 rank, lcolor(gs14)) ///
		(scatter beta rank, mcolor(black) msymbol(oh) msize(small)) ///
		`scoff' `scon' ///
		(scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)), ///
        legend (order(1 "Main spec." 4 "Point estimate" 2 "95% CI" 3 "90% CI") region(lcolor(white)) ///
		region(lcolor(white)) pos(12) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
		graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		xtitle(" ") ytitle(" ") yscale(noline) xscale(noline) ///
		ylab(-0.04(0.02)0.08, format(%9.2fc) noticks nogrid angle(horizontal) labsize(small)) ///
		yline(0, lp(shortdash) lcolor(red) lw(thin)) xlab("", noticks)   
		
		global legend custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))))
		gr_edit .yaxis1.add_ticks -0.05 `"Sample                         "', $legend
		gr_edit .yaxis1.add_ticks -0.05  `"Main  "', $legend
		gr_edit .yaxis1.add_ticks -0.055  `"Full  "', $legend
		gr_edit .yaxis1.add_ticks -0.065 `"Data                         "', $legend
		gr_edit .yaxis1.add_ticks -0.065 `"Books  "', $legend
		gr_edit .yaxis1.add_ticks -0.07 `"School Records  "', $legend
		gr_edit .yaxis1.add_ticks -0.08 `"Controls                         "', $legend
		gr_edit .yaxis1.add_ticks -0.09 `"Period                         "', $legend
		gr_edit .yaxis1.add_ticks -0.09 `"Pooled     "', $legend
		gr_edit .yaxis1.add_ticks -0.095 `"2014     "',$legend
		gr_edit .yaxis1.add_ticks -0.1 `"2015     "', $legend
	
	 gr save "$path/Auxiliary/results/highgrade.gph", replace	
	 gr export "$path/Auxiliary/results/highgrade_rob.png", replace  //wid(500) hei(400) 

//attendance	
	use "$path/Auxiliary/results/attendance_estimates.dta",clear

	//Sort
	gsort -beta
	//Rank 
	gen rank=_n
	//Gen indicators and scatters
		local scoff=" "
		local scon=" "
		local ind=-0.007
		foreach var in main_sample full_sample data_books data_actas controls pooled year_2014 year_2015{
			cap gen i_`var' = `ind'
			local ind = `ind'-0.002
				
			local scoff = "`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs14) $mlabel)" 
			local scon =" `scon' (scatter i_`var' rank if `var'==1, msize(vsmall) mcolor(black))"

			if "`var'" == "data_books" | "`var'" == "data_actas" {
				replace i_`var' = i_`var' - 0.002
			}
			
			if "`var'" == "controls" {
				replace i_`var' = i_`var' - 0.004
			}

			if "`var'" == "pooled" | "`var'" == "year_2014" |  "`var'" == "year_2015"{
				replace i_`var' = i_`var' - 0.006
			}
		}
		 
	tw  (scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)) ///
		(rcap u95 l95 rank, lcolor(gs5)) ///
		(rspike u90 l90 rank, lcolor(gs14)) ///
		(scatter beta rank, mcolor(black) msymbol(oh) msize(small)) ///
		`scoff' `scon' ///
		(scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)), ///
        legend (order(1 "Main spec." 4 "Point estimate" 2 "95% CI" 3 "90% CI") region(lcolor(white)) ///
		region(lcolor(white)) pos(12) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
		graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		xtitle(" ") ytitle(" ") yscale(noline) xscale(noline) ///
		ylab(-0.005(0.005)0.03, format(%9.2fc) noticks nogrid angle(horizontal) labsize(small)) ///
		yline(0, lp(shortdash) lcolor(red) lw(thin)) xlab("", noticks)   

		global legend custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))))
		gr_edit .yaxis1.add_ticks -0.007 `"Sample                          "', $legend
		gr_edit .yaxis1.add_ticks -0.007  `"Main     "', $legend
		gr_edit .yaxis1.add_ticks -0.009  `"Full      "', $legend
		gr_edit .yaxis1.add_ticks -0.013 `"Data                          "', $legend
		gr_edit .yaxis1.add_ticks -0.013 `"Books     "', $legend
		gr_edit .yaxis1.add_ticks -0.015 `"School Records     "', $legend
		gr_edit .yaxis1.add_ticks -0.019 `"Controls                          "', $legend
		gr_edit .yaxis1.add_ticks -0.023 `"Period                           "', $legend
		gr_edit .yaxis1.add_ticks -0.023 `"Pooled     "', $legend
		gr_edit .yaxis1.add_ticks -0.025 `"2014     "',$legend
		gr_edit .yaxis1.add_ticks -0.027 `"2015     "', $legend
		
	
	 gr save "$path/Auxiliary/results/attendance.gph", replace		
	 gr export "$path/Auxiliary/results/attendance_rob.png", replace wid(700) hei(500) 	
	 
//highattendance	
	use "$path/Auxiliary/results/highattendance_estimates.dta",clear

	//Sort
	gsort -beta
	//Rank 
	gen rank=_n
	//Gen indicators and scatters
		local scoff=" "
		local scon=" "
		local ind=-0.05
		foreach var in main_sample full_sample data_books data_actas controls pooled year_2014 year_2015{
			cap gen i_`var' = `ind'
			local ind = `ind'-0.01
				
			local scoff = "`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs14) $mlabel)" 
			local scon =" `scon' (scatter i_`var' rank if `var'==1, msize(vsmall) mcolor(black))"

			if "`var'" == "data_books" | "`var'" == "data_actas" {
				replace i_`var' = i_`var' - 0.01
			}
			
			if "`var'" == "controls" {
				replace i_`var' = i_`var' - 0.02
			}

			if "`var'" == "pooled" | "`var'" == "year_2014" |  "`var'" == "year_2015"{
				replace i_`var' = i_`var' - 0.03
			}
		}
		 
	tw  (scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)) ///
		(rcap u95 l95 rank, lcolor(gs5)) ///
		(rspike u90 l90 rank, lcolor(gs14)) ///
		(scatter beta rank, mcolor(black) msymbol(oh) msize(small)) ///
		`scoff' `scon' ///
		(scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)), ///
        legend (order(1 "Main spec." 4 "Point estimate" 2 "95% CI" 3 "90% CI") region(lcolor(white)) ///
		region(lcolor(white)) pos(12) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
		graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		xtitle(" ") ytitle(" ") yscale(noline) xscale(noline) ///
		ylab(-0.02(0.02)0.16, format(%9.2fc) noticks nogrid angle(horizontal) labsize(small)) ///
		yline(0, lp(shortdash) lcolor(red) lw(thin)) xlab("", noticks)   

		global legend custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))))
		gr_edit .yaxis1.add_ticks -0.05 `"Sample                          "', $legend
		gr_edit .yaxis1.add_ticks -0.05  `"Main     "', $legend
		gr_edit .yaxis1.add_ticks -0.06  `"Full      "', $legend
		gr_edit .yaxis1.add_ticks -0.08 `"Data                          "', $legend
		gr_edit .yaxis1.add_ticks -0.08 `"Books     "', $legend
		gr_edit .yaxis1.add_ticks -0.09 `"School Records     "', $legend
		gr_edit .yaxis1.add_ticks -0.11 `"Controls                          "', $legend
		gr_edit .yaxis1.add_ticks -0.13 `"Period                           "', $legend
		gr_edit .yaxis1.add_ticks -0.13 `"Pooled     "', $legend
		gr_edit .yaxis1.add_ticks -0.14 `"2014     "',$legend
		gr_edit .yaxis1.add_ticks -0.15 `"2015     "', $legend
		
	
	 gr save "$path/Auxiliary/results/highattendance.gph", replace		 
	 gr export "$path/Auxiliary/results/highattendance_rob.png", replace //wid(700) hei(500) 	

//behavior	
	use "$path/Auxiliary/results/beh_neg_std_estimates.dta",clear

	//Sort
	gsort -beta
	//Rank 
	gen rank=_n
	
	gen data_actas=.
	//Gen indicators and scatters
		local scoff=" "
		local scon=" "
		local ind=-0.25
		foreach var in main_sample full_sample data_books data_actas controls pooled year_2014 year_2015{
			cap gen i_`var' = `ind'
			local ind = `ind'-0.02
				
			local scoff = "`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs14) $mlabel)" 
			local scon =" `scon' (scatter i_`var' rank if `var'==1, msize(vsmall) mcolor(black))"

			if "`var'" == "data_books" | "`var'" == "data_actas" {
				replace i_`var' = i_`var' - 0.02
			}
			
			if "`var'" == "controls" {
				replace i_`var' = i_`var' - 0.04
			}

			if "`var'" == "pooled" | "`var'" == "year_2014" |  "`var'" == "year_2015"{
				replace i_`var' = i_`var' - 0.06
			}
		}
		 
	tw  (scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)) ///
		(rcap u95 l95 rank, lcolor(gs5)) ///
		(rspike u90 l90 rank, lcolor(gs14)) ///
		(scatter beta rank, mcolor(black) msymbol(oh) msize(small)) ///
		`scoff' `scon' ///
		(scatter beta rank if main==1, mcolor(blue) msymbol(oh) msize(small)), ///
        legend (order(1 "Main spec." 4 "Point estimate" 2 "95% CI" 3 "90% CI") region(lcolor(white)) ///
		region(lcolor(white)) pos(12) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
		graphregion(fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		xtitle(" ") ytitle(" ") yscale(noline) xscale(noline) ///
		ylab(-0.20(0.05)0.25, format(%9.2fc) noticks nogrid angle(horizontal) labsize(small)) ///
		yline(0, lp(shortdash) lcolor(red) lw(thin)) xlab("", noticks)   

		global legend custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))))
		gr_edit .yaxis1.add_ticks -0.25 `"Sample                          "', $legend
		gr_edit .yaxis1.add_ticks -0.25  `"Main     "', $legend
		gr_edit .yaxis1.add_ticks -0.27	  `"Full      "', $legend
		gr_edit .yaxis1.add_ticks -0.31 `"Data                          "', $legend
		gr_edit .yaxis1.add_ticks -0.31 `"Books     "', $legend
		gr_edit .yaxis1.add_ticks -0.33 `"School Records     "', $legend
		
		gr_edit .yaxis1.add_ticks -0.37 `"Controls                          "', $legend
		gr_edit .yaxis1.add_ticks -0.41 `"Period                           "', $legend
		gr_edit .yaxis1.add_ticks -0.41 `"Pooled     "', $legend
		gr_edit .yaxis1.add_ticks -0.43 `"2014     "',$legend
		gr_edit .yaxis1.add_ticks -0.45 `"2015     "', $legend

	 gr save "$path/Auxiliary/results/behavior.gph", replace	
	 gr export "$path/Auxiliary/results/behavior_rob.png", replace //wid(700) hei(500) 	
	 
	 
/*	 
//combine graphs
	  graph combine "$path/Auxiliary/results/math.gph" "$path/Auxiliary/results/highgrade.gph"   "$path/Auxiliary/results/attendance.gph"  "$path/Auxiliary/results/highattendance.gph"  "$path/Auxiliary/results/behavior.gph", /*
           */ rows(3) imargin(zero) /*
		   */ commonscheme xsize(1.4) ysize(1.1) scale(1) graphregion(margin(zero) fcolor(white) /*
		   */ lcolor(white) ifcolor(white) ilcolor(white)) /*
		   */ plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 	
    graph export "$path/Auxiliary/results/fig_robustness.gph", as(png) replace
*/
   //erase
   foreach var in math highgrade attendance highattendance behavior{
		erase "$path/Auxiliary/results/`var'.gph"
   }
   foreach var in attendance highgrade math_std highattendance beh_neg_std{
		erase "$path/Auxiliary/results/`var'_estimates.dta"
   }   
   
   